$(document).ready(function(){
	var contextPath = document.location.pathname;
	var index = contextPath.substr(1).indexOf("/");
	contextPath = contextPath.substr(1, index);
	var basePath = "/" + contextPath;
	initProvince();
	var province = null;
	var city = null;
	var area = null;
	
	
	
	
	/**
	 * 初始化省份
	 */
	function initProvince(){
		 var seachprov = $("#seachprov");
			var editUrl = basePath+"/HRTWEB/address/province/list.do";
			$.ajax({

				url : editUrl,
				dataType : 'json',
				cache : false,

				success : function(data) {
					var results = data.provinceList;
					
					var rowContent = "<option  value ='-1' >请选择</option>";
					if(results!=null){
						
						for(i=0;i<results.length;i++){
							var province =results[i];
							rowContent = rowContent+"<option  value ="+province.code+" >"+province.name+"</option>";
						}
					}
					seachprov.append(rowContent);
				},
				error : function(html) {
					alert("Load Data failly");
					refresh();
				}
			});
	}
	
});



function pickDate(){
	laydate({
        elem: '#myborth',
        format: 'YYYY-MM-DD',
        festival: true, //显示节日
    });
}





function changeComplexProvince(provincecode) {
		$("#seachcity").empty(); //改变省份时先清空原先的市
		$("#seachdistrict").empty();
		var seachcity = $("#seachcity");
		province = $("#seachprov option:selected").text();
		
		var editUrl ="/HRTWeb3/HRTWEB/address/city/list.do?";
		$.ajax({

			url : editUrl,
			dataType : 'json',
			cache : false,
			data : {
				provincecode : provincecode
			},
			success : function(data) {
				var results = data.cityList;
				
				var rowContent = "<option  value ='-1' >请选择</option>";
				if(results!=null){
					
					for(i=0;i<results.length;i++){
						var city =results[i];
						rowContent = rowContent+"<option  value ="+city.code+" >"+city.name+"</option>";
					}
				}
				seachcity.append(rowContent);
			},
			error : function(html) {
				alert("Load Data failly");
				refresh();
			}
		});
	
  
}

 
function changeCity(citycode) {
	$("#seachdistrict").empty(); //改变城市时先删除原先的区
	var seachdistrict = $("#seachdistrict");
	
	city = $("#seachcity option:selected").text();
	
	
	var editUrl ="/HRTWeb3/HRTWEB/address/area/list.do?";
	$.ajax({

		url : editUrl,
		dataType : 'json',
		cache : false,
		data : {
			citycode : citycode
		},
		success : function(data) {
			var results = data.areaList;
			
			var rowContent = "<option  value ='-1' >请选择</option>";
			if(results!=null){
				
				for(i=0;i<results.length;i++){
					var area =results[i];
					rowContent = rowContent+"<option  value ="+area.code+" >"+area.name+"</option>";
				}
			}
			seachdistrict.append(rowContent);
		},
		error : function(html) {
			alert("Load Data failly");
			refresh();
		}
	});
    
}
function changeArea(areacode){
	area = $("#seachdistrict option:selected").text();
	
	var address = province+city+area;
	
	$("#address").val(address);
	
}


function clearAddress() {
	$("#seachprov").empty(); 
	$("#seachcity").empty(); 
	$("#seachdistrict").empty(); 
}
